<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$return['banner']=$basic['image'];
if($_RQ['op']=='main'){
	//查询设计师
	$list=pdo_getall('jy_cmsdecorate_stylist',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1'));
	if($list){
		foreach($list as &$item){
			$item['lev_name']=pdo_getcolumn('jy_cmsdecorate_lev',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['lev_id']),'lev_name');
			$item['cname']=pdo_getcolumn('jy_cmsdecorate_company',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['cid']),'title');
		    //已支付，已确认，已完成订单数
			$num1=pdo_count('jy_cmsdecorate_order',array('uniacid'=>$_SESSION['uniacid'],'sid'=>$item['id'],'status'=>'1'));
			$num2=pdo_count('jy_cmsdecorate_order',array('uniacid'=>$_SESSION['uniacid'],'sid'=>$item['id'],'status'=>'2'));
			$num3=pdo_count('jy_cmsdecorate_order',array('uniacid'=>$_SESSION['uniacid'],'sid'=>$item['id'],'status'=>'4'));
			$item['num']=$num1+$num2+$num3;
		}
	}
	$return['post']=array();
	$return['list']=$list;
	//print_r($return);exit;
	exi($return);
}
if($_RQ['op']=='list'){

	exi($return);
}
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
		exi('没有找到该设计师，请重新选择！','error','jy_cmsdecorate/stylist/main');
	}
	//查询该员工具体信息
	$stylister=pdo_get('jy_cmsdecorate_stylist',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//等级名称
	$lev_name=pdo_getcolumn('jy_cmsdecorate_lev',array('uniacid'=>$_SESSION['uniacid'],'id'=>$sylister['lev_id']),'lev_name');
	$return['stylister']=$stylister;
	$return['lev_name']=$lev_name;
	$return['post']=array();
	$this->session('sid',$_RQ['id']);
	//print_r($return);exit;
	exi($return);
}
if($_RQ['op']=='notice'){
	$return['info']=array();
	//print_r($return);exit;
	exi($return);	
}
if($_RQ['op']=='case'){
	$sid = $this->session('sid');
	$case=pdo_getall('jy_cmsdecorate_case',array('uniacid'=>$_SESSION['uniacid'],'sid'=>$sid));
	foreach($case as &$v){
		if($v['ishot']){
			$v['ishot']='热门';
		}else{
			$v['ishot']='';
		}
	}
	$return['list']=$case;	
	exi($return);
}
if($_RQ['op']=='submit'){

    $postdata=get_postdata();
	if(!$postdata['name']){
		exi('请输入您的姓名','error');
	}
	if(!$postdata['mobile']){
		exi('请输入您的电话','error');
	}
	if(!preg_match("/^1[345678]{1}\d{9}$/",$postdata['mobile'])){  
	 
		exi('请输入正确的手机号码','error');
	} 
	if(!$postdata['address']){
		exi('请输入装修地址','error');
	}
	$cid=pdo_getcolumn('jy_cmsdecorate_stylist',array('uniacid'=>$_SESSION['uniacid'],'id'=>$this->session('sid')),'cid');
	if($postdata){
	$insert=array(
	'uniacid'=>$_SESSION['uniacid'],
	'user_id'=>$_SESSION['uid'],
	'cid'=>$cid,
	'sid'=>$this->session('sid'),
	'address'=>$postdata['address'],
	'remark'=>$postdata['remark'],
	'ordersn'=>get_ordersn('jy_cmsdecorate_order','ordersn'),
	'status'=>1,
	'createtime'=>TIMESTAMP,
	);
	pdo_insert('jy_cmsdecorate_order',$insert);
	$id=pdo_insertid();
	$update=array(
		'realname'=>$postdata['name'],
		'mobile'=>$postdata['mobile'],
	);
	pdo_update('core_members',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['uid']));
	exi('提交成功','','jy_cmsdecorate/order/list/status=1');
		}	
	$return['cid']=$cid;
	$return['info']=array();
	exi($return);
}